< previous page page_152 next page >

Page 152
The vertical line in the preceding code line is known as the pipe symbol. This symbol must be present in the filter. Preceding the pipe symbol is a short description of the file type, in this case Word Documents (*.doc). Following the pipe symbol is the actual filter for the files. You typically express the filter as an asterisk followed by a period and the extension of the files that you want to display. Some examples are *.txt, *.doc, and *.*.
If you specify the Filter property with an assignment statement, you must enclose the filter in double quotation marks, as with any string. The quotes are omitted if you specify the filter from the Properties dialog box.
You can specify multiple description|filter pairs within the Filter property. Each pair must be separated from the other pairs by the pipe symbol, as shown in the following example:
cdlTest.Filter = "Text Files|*.txt|All Files|*.*"
To see the Filter property in action, replace the code in the test project's cmdTest_Click event procedure with these lines, and then run the program:
cdlTest.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
cdlTest.ShowOpen
When you test this code, note that the CommonDialog control's Filter property causes only text files to be displayed, unless the user selects another filter by dropping down the Files of type drop-down list.
Customizing the File Dialog Boxes with the Flags Property
Another important property is the Flags property. The Flags property is set using a constant or combination of constants, similar to the MsgBox function's Options parameter. A complete list of constants is listed in Visual Basic's Help system. For example, if the Open as Read Only check box doesn't make any sense in your program, you can set a flag to hide it, like this:
cdlTest.Flags = cdlOFNHideReadOnly
cdlTest.InitDir = "C:\Windows"
cdlTest.ShowOpen
Note also the use of the InitDir property, which starts the dialog box in a specific folder.
CAUTION
Flags, Filters, and other properties that affect the CommonDialog control must be set before displaying it.

The Font Dialog Box
Setting up the CommonDialog control to show the Font dialog box is just as easy as setting it up for file functions. In fact, you can use the same CommonDialog control on a form to handle file, font, color, and printer functions, just by resetting the properties and invoking the appropriate method.

 
< previous page page_152 next page >